package com.huluobo.a2107kotlinshopping.register

import androidx.lifecycle.MutableLiveData
import com.google.gson.Gson
import com.huluobo.a2107kotlinshopping.base.BaseViewModel
import com.huluobo.a2107kotlinshopping.login.UserBeanResult
import com.huluobo.a2107kotlinshopping.net.Const
import okhttp3.MediaType
import okhttp3.RequestBody

/**
 *  Created by LC on 2023/11/14.
 */
class RegisterViewModel : BaseViewModel() {
    val registerSuccess = MutableLiveData<UserBeanResult>()
    val registerFailed = MutableLiveData<String>()
    private val repo = RegisterRepo()

    fun register(username: String, password: String, repassword: String) {
        val map = mutableMapOf<String, String>()
        map[Const.PARAM_USERNAME] = username
        map[Const.PARAM_PASSWORD] = password
        map[Const.PARAM_RE_PASSWORD] = repassword
        val json = Gson().toJson(map)
        val body = RequestBody.create(MediaType.parse(Const.MEDIA_PARSE), json)
        repo.register(body, registerSuccess, registerFailed)
    }
}